window.runScript = function(script) {
   try {
      eval(script);
   }
   catch(ex) {
      alert(ex);
   }
}

String.prototype.lTrim = function() {
   return this.replace(/(^[\\s]*)/g, "");
}

String.prototype.rTrim = function() {
   return this.replace(/([\\s]*$)/g, "");
}

String.prototype.trim = function() {
   return this.replace(/(^\s*)|(\s*$)/g,"");
}

String.prototype.chineseLength = function() {
   return this.replace(/[^\x00-\xff]/g,"**").length;
}

String.prototype.endsWith = function(str) {
   return this.substr(this.length - str.length) == str;
}

String.prototype.startsWith = function(str) {
   return this.substr(0, str.length) == str;
}

String.prototype.equals = function(str) {
   return this == str;
}

String.prototype.equalsIgnoreCase = function(str) {
   return this.toLowerCase() == str.toLowerCase();
}

String.prototype.isMobile = function() {
   return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.trim()));
}

String.prototype.isStrictTel = function() {
    //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
    return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(
       this.trim()));
}

String.prototype.isTel = function() {
   return (/^([\d-+]*)$/.test(this.trim()));
}

Date.prototype.format = function(format) {
   var o = {
      "M+" : this.getMonth() + 1, //month
      "d+" : this.getDate(), //day
      "h+" : this.getHours(), //hour
      "m+" : this.getMinutes(), //minute
      "s+" : this.getSeconds(), //second
      "q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
      "S" : this.getMilliseconds()
   // millisecond
   }

   if(/(y+)/.test(format)) {
      format = format.replace(RegExp.$1, (this.getFullYear() + "")
         .substr(4 - RegExp.$1.length));
   }

   for(var k in o) {
      if(new RegExp("(" + k + ")").test(format)) {
         format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
            : ("00" + o[k]).substr(("" + o[k]).length));
      }
   }

   return format;
}